package com.fbt.energy.controller;

import com.fbt.energy.entity.ExceptionRecord;
import com.fbt.energy.service.ExceptionRecordService;

import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 能耗异常表(ExceptionRecord)表控制层
 *
 * @author makejava
 * @since 2021-12-12 19:06:38
 */
@CrossOrigin
@RestController
@Api(tags = {"能耗异常表(ExceptionRecord)表控制层"})
@RequestMapping("/exceptionRecord")
public class ExceptionRecordController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ExceptionRecordService exceptionRecordService;

    /**
     * 分页查询
     *
     * @param exceptionRecord 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Log(title="能耗异常表")
    @ApiOperation("分页查询列表")
    @GetMapping
    public ResponseEntity<Page<ExceptionRecord>> queryByPage(ExceptionRecord exceptionRecord, PageRequest pageRequest) {
        return ResponseEntity.ok(this.exceptionRecordService.queryByPage(exceptionRecord, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */

    @Log(title="能耗异常表")
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("/{id}")
    public ResponseEntity<ExceptionRecord> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.exceptionRecordService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param exceptionRecord 实体
     * @return 新增结果
     */
    @Log(title="能耗异常表",businessType= BusinessType.INSERT)
    @ApiOperation("新增数据")
    @PostMapping
    public ResponseEntity<ExceptionRecord> add(ExceptionRecord exceptionRecord) {
        return ResponseEntity.ok(this.exceptionRecordService.insert(exceptionRecord));
    }

    /**
     * 编辑数据
     *
     * @param exceptionRecord 实体
     * @return 编辑结果
     */
    @Log(title="能耗异常表",businessType=BusinessType.UPDATE)
    @ApiOperation("修改数据")
    @PutMapping
    public ResponseEntity<ExceptionRecord> edit(ExceptionRecord exceptionRecord) {
        return ResponseEntity.ok(this.exceptionRecordService.update(exceptionRecord));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @Log(title="能耗异常表",businessType=BusinessType.DELETE)
    @ApiOperation("根据主键删除数据")
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.exceptionRecordService.deleteById(id));
    }

}

